package com.dcbeida.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.bean.Patient;

import java.util.ArrayList;

/**
 * Created by fancl on 2016/8/8.
 */
public class ListPopupWindowAdapter extends BaseAdapter {

    private ArrayList<Patient> mArrayList;
    private Context mContext;
    private int type;

    public ListPopupWindowAdapter(ArrayList<Patient> list, Context context) {
        super();
        this.mArrayList = list;
        this.mContext = context;
    }

    public ListPopupWindowAdapter(Context context) {
        super();
        this.mContext = context;
    }


    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.patientinfo_item, null, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Patient s1 = mArrayList.get(position);
        holder.tv_item_idcard.setText(mContext.getString(R.string.hzformat, s1.getIdcardnum()));
        holder.tv_item_name.setText(mContext.getString(R.string.hznameformat, s1.getTruename()));
        holder.tv_item_tel.setText(mContext.getString(R.string.hztelformat, s1.getPhonenum()));
        if(type==0){
            holder.tv_item_tel.setVisibility(View.GONE);
            holder.tv_item_idcard.setVisibility(View.VISIBLE);
            holder.tv_item_name.setVisibility(View.VISIBLE);
        }else if(type==1){
            holder.tv_item_tel.setVisibility(View.VISIBLE);
            holder.tv_item_idcard.setVisibility(View.GONE);
            holder.tv_item_name.setVisibility(View.VISIBLE);
        }else if(type==2){
            holder.tv_item_tel.setVisibility(View.VISIBLE);
            holder.tv_item_idcard.setVisibility(View.VISIBLE);
            holder.tv_item_name.setVisibility(View.GONE);
        }else {
            holder.tv_item_tel.setVisibility(View.VISIBLE);
            holder.tv_item_idcard.setVisibility(View.VISIBLE);
            holder.tv_item_name.setVisibility(View.GONE);
        }

        return convertView;
    }

    private class ViewHolder {
        TextView tv_item_tel;
        TextView tv_item_idcard;
        TextView tv_item_name;

        ViewHolder(View view) {
            tv_item_idcard = (TextView) view.findViewById(R.id.tv_item_idcard);
            tv_item_name = (TextView) view.findViewById(R.id.tv_item_name);
            tv_item_tel = (TextView) view.findViewById(R.id.tv_item_tel);
        }

    }

    public ArrayList<Patient> getmArrayList() {
        return mArrayList;
    }

    public void setmArrayList(ArrayList<Patient> mArrayList) {
        this.mArrayList = mArrayList;
        notifyDataSetChanged();
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }
}
